package com.briup.cms.web.controller;

import com.briup.cms.bean.Carousel;
import com.briup.cms.service.ICarouselService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图相关接口
 **/
@Api(tags="轮播图相关接口")
@RestController
@RequestMapping("/auth/carousel")
public class CarouselController {

    @Autowired
    private ICarouselService carouselService;

    @ApiOperation(value = "查询所有轮播图",notes = "分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
    })
    @GetMapping("/page/query")
    public Message pageQuery(int pageNum, int pageSize){
        PageInfo<Carousel> data = carouselService.findAll(pageNum,pageSize);
        return MessageUtil.success(data);
    }

    @ApiOperation(value = "查询所有已经启用的轮播图",notes = "不分页")
    @GetMapping("/find/yes")
    public Message findYseAll(){
        List<Carousel> list = carouselService.findYseAll();
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除轮播图")
    @DeleteMapping("/deleteById")
    public Message deleteById(int id){
        carouselService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存轮播图信息")
    @PostMapping("/save")
    public Message saveCarousel(Carousel carousel ){
        carouselService.saveCarousel(carousel);
        return MessageUtil.success("轮播图保存成功");
    }

    @ApiOperation(value = "更新轮播图信息")
    @PutMapping("/update")
    public Message updateCarousel(Carousel carousel ){
        carouselService.updateCarousel(carousel);
        return MessageUtil.success("轮播图信息更新成功");
    }

}
